package com.neuedu.boot;

import org.jshand.boot.MyFilter;
import org.jshand.boot.MyListener;
import org.jshand.boot.MyServlet;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.MultipartConfigElement;

/**
 * Hello world!
 *
 */
@SpringBootApplication
// @ServletComponentScan(basePackages="org.jshand.boot")    //第一种包扫描的方式
public class AppWebComponent
{

    public static void main( String[] args )
    {
        SpringApplication.run(AppWebComponent.class, args);
    }

    @Bean
    public ServletRegistrationBean registrationBean() {


        //注册Servlet   url  --- 类映射  web.xml
        // ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet2","/myServlet3");
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setServlet(new MyServlet());
        registrationBean.addUrlMappings("/myServlet2","/myServlet3");

        return registrationBean;
    }



    @Bean
    public FilterRegistrationBean filterRegistrationBean() {


        //注册Servlet   url  --- 类映射  web.xml
        // ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet2","/myServlet3");
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new MyFilter());
        filterRegistrationBean.addUrlPatterns("/*");

        return filterRegistrationBean;
    }


    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean() {


      ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
        servletListenerRegistrationBean.setListener(new MyListener());
        return servletListenerRegistrationBean;
    }


}
